home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / dte5_1.zip / HWIND.C < prev    next >
C/C++ Source or Header  |  1991-02-06  |  20KB  |  646 lines

  1. /*
  2.  * Written by Douglas Thomson (1989/1990)
  3.  *
  4.  * This source code is released into the public domain.
  5.  */
  6.  
  7. /*
  8.  * Name:    hardware independent screen IO module
  9.  * Purpose: This file contains the code to interface the rest of the
  10.  *           editor to the display and input hardware.
  11.  * File:    hwind.c
  12.  * Author:  Douglas Thomson
  13.  * System:  this file is intended to be system-independent
  14.  * Date:    October 2, 1989
  15.  * Notes:   This is the only module that is allowed to call the hardware
  16.  *           dependent display IO library.
  17.  *          Typically, functions here check whether any action is
  18.  *           necessary (for example, the cursor may already happen to be
  19.  *           in the required position), call hardware dependent functions
  20.  *           to achieve the required effect, and finally update status
  21.  *           information about the current state of the terminal display.
  22.  *          The idea behind this approach is to keep the hardware
  23.  *           dependent code as small and simple as possible, thus making
  24.  *           porting the code easier.
  25.  */
  26.  
  27. #ifdef HPXL
  28. #include "commonh"
  29. #include "hwdeph"
  30. #else
  31. #include "common.h"
  32. #include "hwdep.h"
  33. #endif
  34. #include <string.h>
  35.  
  36. /*
  37.  * prototypes for all functions in this file
  38.  */
  39. void xygoto ARGS((int col, int line));
  40. void set_attr ARGS((char attr));
  41. int c_insert ARGS((void));
  42. int c_delete ARGS((void));
  43. int eol_clear ARGS((void));
  44. int c_avail ARGS((void));
  45. int c_input ARGS((void));
  46. void c_uninput ARGS((char c));
  47. void c_output ARGS((int c));
  48. void s_output ARGS((char *s));
  49. void force_blank ARGS((void));
  50. void initialize ARGS((void));
  51. void terminate ARGS((void));
  52. void line_del ARGS((int line));
  53. void line_ins ARGS((int ins_line));
  54. void window_scroll_up ARGS((int top, int bottom));
  55. void window_scroll_down ARGS((int top, int bottom));
  56.  
  57. /*
  58.  * Name:    xygoto
  59.  * Purpose: To move the cursor to the required column and line.
  60.  * Date:    October 2, 1989
  61.  * Passed:  col:    desired column (0 up to max)
  62.  *          line:   desired line (0 up to max)
  63.  * Notes:   This function makes some attempt to use shorter movement
  64.  *           commands for simple movements (initially, only backspace
  65.  *           to move left one space).
  66.  */
  67. void xygoto(col, line)
  68. int col;
  69. int line;
  70. {
  71.     int diff;  /* how far backwards the cursor must be moved */
  72.  
  73.     /*
  74.      * If the cursor is on the right line, then a simpler movement
  75.      *  may be possible.
  76.      */
  77.     if (g_display.line == line) {
  78.         if ((diff = g_display.col - col) == 0) {
  79.             /*
  80.              * the cursor was in exactly the right spot, so no
  81.              *  action required.
  82.              */
  83.             return;
  84.         }
  85.         else if (diff == 1) {
  86.             /*
  87.              * the cursor only needs to move one space left, so try
  88.              *  simply backspacing (if the hardware supports it)
  89.              */
  90.             if (hw_backspace()) {
  91.                 g_display.col = col;
  92.                 return;
  93.             }
  94.         }
  95.     }
  96.  
  97.     /*
  98.      * use a full cursor addressing command. The hardware is required
  99.      *  to provide such a command, so there is no need to check.
  100.      */
  101.     g_display.col = col;
  102.     g_display.line = line;
  103.     hw_xygoto();
  104. }
  105.  
  106. /*
  107.  * Name:    set_attr
  108.  * Purpose: To record the attribute to be used for the next character
  109.  *           output.
  110.  * Date:    October 2, 1989
  111.  * Passed:  attr:              desired new attribute
  112.  * Returns: [g_status.wanted]: attribute to use next
  113.  * Notes:   Since other hardware commands can need to fiddle with the
  114.  *           attribute, it is better not to bother actually outputting
  115.  *           the hardware attribute command. This is done immediately
  116.  *           prior to sending the actual character.
  117.  */
  118. void set_attr(attr)
  119. char attr;
  120. {
  121.     g_status.wanted = attr;
  122. }
  123.  
  124. /*
  125.  * Name:    c_insert
  126.  * Purpose: To insert space for one character at the cursor position.
  127.  * Date:    October 2, 1989
  128.  * Notes:   If this function is available in the hardware, then it must
  129.  *           leave the cursor in its original position (or else
  130.  *           explicitly undefined [line = col = -1]) and insert one
  131.  *           character in front of the character that used to be under
  132.  *           the cursor.
  133.  *          No assumption is made about what the attribute of the inserted
  134.  *           character will be!
  135.  */
  136. int c_insert()
  137. {
  138.     int col;        /* used to copy characters along */
  139.     int old_col;    /* to remember current column */
  140.     int old_line;   /* to remember current line */
  141.  
  142.     /*
  143.      * It is permissible for hardware functions to leave the current
  144.      *  cursor position undefined (-1, -1). Hence we need to store the
  145.      *  current location for use later.
  146.      */
  147.     old_col = g_display.col;
  148.     old_line = g_display.line;
  149.  
  150.     if (hw_c_insert()) {
  151.         /*
  152.          * update memory version of screen
  153.          */
  154.         for (col=g_display.ncols-1; col > old_col; col--) {
  155.             g_screen[old_line][col] =
  156.                     g_screen[old_line][col-1];
  157.         }
  158.         g_screen[old_line][old_col].c = ' ';
  159.         g_screen[old_line][old_col].attr = 0xFF;
  160.         return TRUE;
  161.     }
  162.     return FALSE;
  163. }
  164.  
  165. /*
  166.  * Name:    c_delete
  167.  * Purpose: To delete the character under the cursor.
  168.  * Date:    October 10, 1989
  169.  * Notes:   If this function is available in the hardware, then it must
  170.  *           leave the cursor in its original position (or else
  171.  *           explicitly undefined [line = col = -1]) and delete the
  172.  *           character under the cursor.
  173.  *          The character which appears at the end of the line after the
  174.  *           delete is assumed to be a space with the normal attribute.
  175.  */
  176. int c_delete()
  177. {
  178.     int col;        /* used to copy characters along */
  179.     int old_col;    /* to remember current column */
  180.     int old_line;   /* to remember current line */
  181.  
  182.     /*
  183.      * It is permissible for hardware functions to leave the current
  184.      *  cursor position undefined (-1, -1). Hence we need to store the
  185.      *  current location for use later.
  186.      */
  187.     old_col = g_display.col;
  188.     old_line = g_display.line;
  189.  
  190.     if (hw_c_delete()) {
  191.         /*
  192.          * update memory version of screen
  193.          */
  194.         for (col=old_col; col < g_display.ncols-1; col++) {
  195.             g_screen[old_line][col] =
  196.                     g_screen[old_line][col+1];
  197.         }
  198.         g_screen[old_line][g_display.ncols-1].c = ' ';
  199.         g_screen[old_line][g_display.ncols-1].attr = g_display.normal;
  200.         return TRUE;
  201.     }
  202.     return FALSE;
  203. }
  204.  
  205. /*
  206.  * Name:    eol_clear
  207.  * Purpose: To clear the current line from the cursor to the end of the
  208.  *           line to normal spaces.
  209.  * Date:    October 2, 1989
  210.  * Notes:   If this function is available in the hardware, then it must
  211.  *           clear all the rest of the line to spaces, all with the normal
  212.  *           attribute, and leave the cursor exactly where it was (or else
  213.  *           explicitly undefined [line = col = -1]).
  214.  */
  215. int eol_clear()
  216. {
  217.     int col;
  218.     int old_col;    /* to remember current column */
  219.     int old_line;   /* to remember current line */
  220.  
  221.     old_col = g_display.col;
  222.     old_line = g_display.line;
  223.  
  224.     if (!hw_clreol()) {
  225.         return FALSE;
  226.     }
  227.     for (col=old_col; col < g_display.ncols; col++) {
  228.         g_screen[old_line][col].c = ' ';
  229.         g_screen[old_line][col].attr = g_display.normal;
  230.     }
  231.     return TRUE;
  232. }
  233.  
  234. /*
  235.  * Name:    c_avail
  236.  * Purpose: To test whether or not there is a character available to be
  237.  *           read from the user.
  238.  * Date:    October 2, 1989
  239.  * Notes:   Under some circumstances it is convenient to be able to push
  240.  *           a few characters back into the input stream, making it appear
  241.  *           to the rest of the editor that the user typed something
  242.  *           different (for example, the tab key might be turning into
  243.  *           the required number of spaces).
  244.  */
  245. int c_avail()
  246. {
  247.     if (g_status.ungotcount) {
  248.         return TRUE;
  249.     }
  250.     return hw_c_av